/*
 * @lc app=leetcode.cn id=167 lang=javascript
 *
 * [167] 两数之和 II - 输入有序数组
 */

// @lc code=start
/**
 * @param {number[]} numbers
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function(numbers, target) {
    let left=0,right=numbers.length-1
    while(left<right){
        let l=numbers[left]
        let r=numbers[right]
        if(l+r===target){
            return[++left,++right]
        }else if(l+r<target){
            ++left
        }else{
            --right
        }
    }
};
// @lc code=end
var twoSum = function(numbers, target) {
    let map=new Map()
    let len=numbers.length
    let left=0,right=len-1
    for(let i=0;i<len;i++){
        left=i+1
        let mid=(left+right)>>1
        let found=target-numbers[i]
        while(left<=right){
            if(numbers[mid]===found){
                return [i+1,mid+1]
            }else if(numbers[mid]<found){
                left++
            }else{
                right--
            }
            mid=(left+right)>>1
        }
    }
};//二分法
